#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from enum import Enum
from common.env_common import get_install_head_path


class CommandReturnCode(int, Enum):
    # cmd return value
    SUCCESS = 0
    FAILED = 1


class NodeRole(int, Enum):
    MASTER = 1
    SLAVE = 2
    DATA = 3


class ListTargetObject(Enum):
    CURRENT = 'current'
    CHILDREN = 'children'


class DeviceType(str, Enum):
    MRS = 'mrs'


class KerberosConstant(str, Enum):
    KRB5_CONF = "krb5Conf"
    CONFIG_MODEL = 'configModel'
    KEYTAB_MODEL = 'keytab_model'
    PASSWORD_MODEL = 'password_model'
    KEYTAB = 'keytab'
    SECRET = 'secret'


class RedisNodeKeyConstant(str, Enum):
    VERSION = 'redis_version'
    ROLE = 'role'
    AOF_ENABLED = 'aof_enabled'
    IP = 'ip'
    PORT = 'port'
    MASTER_HOST = 'master_host'
    MASTER_PORT = 'master_port'


class RedisCmdRetKey(str, Enum):
    CLIENT_NOT_FOUND = 'not found'
    INFORMATION_ERROR = 'information error'
    NO_SUIT_KEY = 'no suitable keys'


class RedisPluginPathConstant(str, Enum):
    TMP_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/stmp/'
    DB_BIN_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/Plugins/GeneralDBPlugin/bin/'


class AccessPermission(Enum):
    RWX_RX_RX = 0o755


class ErrorCode(int, Enum):
    SUCCESS = 0
    ERROR_NETWORK_CONNECT_TIMEOUT = 0x5E025063  # 1577209955
    ERROR_INTERNAL = 0x5F025101  # 1593987329
    ERR_PLUGIN_CANNOT_BACKUP = 0x64032B0C  # 1677929228
    ERR_EXIST_RUNNING_NODE = 0x64033A0A  # 1677933066
    ERR_AOF_ENABLE = 0x64033A0B  # 1677933067


class ProgressType(str, Enum):
    RESTORE_PREREQUISITE = 'restore_prerequisite'
    RESTORE = 'restore'
    RESTORE_POST = 'restore_post'
    BACKUP = 'backup'


class SubJobType(int, Enum):
    PRE_SUB_JOB = 0
    GENERATE_SUB_JOB = 1
    BUSINESS_SUB_JOB = 2
    POST_SUB_JOB = 3


class ExecutePolicy(int, Enum):
    ANY_NODE = 0
    LOCAL_NODE = 1
    EVERY_NODE_ONE_TIME = 2
    RETRY_OTHER_NODE_WHEN_FAILED = 3
    FIXED_NODE = 4


class RestoreProgressPhase(int, Enum):
    BEGIN_CHECK_NODE_ALLOW_RESTORE = 5
    END_CHECK_NODE_ALLOW_RESTORE = 10
    END_COPY_FILE = 95
    COMPLETE = 100


class NodeStatus(int, Enum):
    ONLINE = 27
    OFFLINE = 28


class ExtendInfo(str, Enum):
    IP = 'ip'
    PORT = 'port'
    ROLE = 'role'
    AGENT_ID = 'agentId'
    STATUS = 'status'
    ID = 'id'
    DIR = 'dir'
    DBFILENAME = 'dbfilename'
    PAIR = 'pair'
    COPY_ID = 'copyId'
    AUTH = 'auth'


class BackupJobParam(str, Enum):
    JOB = 'job'
    SUBJOB = 'subJob'
    PROTECT_ENV = 'protectEnv'
    NODES = 'nodes'
    JOB_INFO = 'jobInfo'
    EXTEND_INFO = 'extendInfo'
    AUTH = 'auth'
    ID = 'id'
    REPOSITORIES = 'repositories'
    REPOSITORY_TYPE = 'repositoryType'
    REMOTE_PATH = 'remotePath'
    COPY = 'copy'
    BACKUP_JOB_RESULT = 'backupJobResult'


class BackupRedisCmd(str, Enum):
    LASTSAVE = 'lastsave'
    BGSAVE = 'bgsave'


class BackupJobResult(int, Enum):
    SUCCESS = 0
    FAILED = 1
    ABORTED = 2


class LogLevel(int, Enum):
    INFO = 1
    WARN = 2
    ERROR = 3
    SERIOUS = 4


class SysStdData:
    SYS_STDIN = ''


class FormatCapacity(int, Enum):
    BASE_SIZE = 1024
    KB_SIZE = BASE_SIZE
    MB_SIZE = BASE_SIZE * KB_SIZE
    GB_SIZE = BASE_SIZE * MB_SIZE
    TB_SIZE = BASE_SIZE * GB_SIZE
